package com.zhuandaonet.manager.service.impl;

import com.zhuandaonet.common.exception.ServiceException;
import com.zhuandaonet.manager.dao.RoleDao;
import com.zhuandaonet.manager.entity.RoleEntity;
import com.zhuandaonet.manager.req.RoleReq;
import com.zhuandaonet.manager.resp.RoleResp;
import com.zhuandaonet.manager.service.RoleJpaService;
import com.zhuandaonet.manager.service.RoleService;
import com.zhuandaonet.springjpa.dao.IDao;
import com.zhuandaonet.springjpa.service.IService;
import com.zhuandaonet.springjpa.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleEntity,String> implements RoleService, RoleJpaService {

    @Autowired
    private RoleDao roleDao;

    @Override

    public RoleResp add(RoleReq req) throws ServiceException {
        RoleEntity entity = new RoleEntity();
        BeanUtils.copyProperties(req,entity);
        RoleEntity roleEntity = this.save(entity);
        return roleEntity.toResp();
    }

    @Override
    public RoleResp update(RoleReq req) throws ServiceException {
        RoleEntity entity = new RoleEntity();
        BeanUtils.copyProperties(req,entity);
        RoleEntity roleEntity = this.save(entity);
        return roleEntity.toResp();
    }

    @Override
    public RoleResp get(String id) throws ServiceException {
        return this.getOneById(id).toResp();
    }

    @Override
    public IDao getRepository() {
        return roleDao;
    }

    @Override
    public Page<RoleEntity> findAll(RoleEntity roleEntity, Pageable pageable) throws ServiceException {
        return null;
    }
}
